package com.hd.core.project.module.service;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.hd.core.project.module.domain.EduUploadData;
import com.hd.core.project.module.domain.EduUploadDataTeacher;
import com.hd.core.project.module.domain.EduUploadDataTitle;
import com.hd.core.project.module.mapper.EduUploadDataMapper;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 教务科-上传资料 服务层实现
 * 
 * @author RichardTang
 * @date 2018-08-02
 */
@Service
@SuppressWarnings("all")
public class EduUploadDataService extends ServiceImpl<EduUploadDataMapper,EduUploadData> {

    @Autowired
    private EduUploadDataTitleService eduUploadDataTitleService;

    @Autowired
    private EduUploadDataTeacherService eduUploadDataTeacherService;

    /**
     * 插入解析之后的数据
     * @return
     * @param parseResult
     */
    public boolean insertParseAfterData(Map<String, List> parseResult){
        List<EduUploadDataTitle> eduTitle = (List<EduUploadDataTitle>)parseResult.get("eduTitle");
        List<List<EduUploadDataTeacher>> eduTeacher = (List<List<EduUploadDataTeacher>>)parseResult.get("eduTeacher");
        eduUploadDataTitleService.insertOrUpdateAllColumnBatch(eduTitle);
        for(List<EduUploadDataTeacher> itemList : eduTeacher){
            for(EduUploadDataTeacher teacher : itemList){
                //先查询 TODO 这里并没有处理name重名的情况 后期解决
                int teacherId = eduUploadDataTeacherService.selectIdByNameYearMonth(teacher);
                if(teacherId > 0){
                    teacher.setId((long)teacherId);
                }
            }
            eduUploadDataTeacherService.insertOrUpdateBatch(itemList);
        }
        return true;
    }
}
